package com.wyy.mall.tiny.component;

import com.wyy.mall.tiny.service.OmsPortalOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 取消订单消息的处理者
 * created by 伍猷煜 on 2021/5/25 14:37 星期二
 */
@Component
// 接受来自mall.order.cancel的消息
@RabbitListener(queues = "mall.order.cancel")
public class CancelOrderReceiver {

    private static Logger LOGGER = LoggerFactory.getLogger(CancelOrderReceiver.class);

    private final OmsPortalOrderService mOmsPortalOrderService;
    @Autowired
    public CancelOrderReceiver(OmsPortalOrderService omsPortalOrderService) {
        mOmsPortalOrderService = omsPortalOrderService;
    }

    @RabbitHandler
    public void handle(Long orderId) {
        LOGGER.info("receive delay message orderId:{}", orderId);
        // TODO 这里个人认为还需要判断订单是否支付，已支付的就过滤掉。未支付的就取消，另外暂时未搞懂为什么要用两个消息队列，
        // TODO 一个延迟消息队列好像就可以了吧。猜测可能是为了更好的处理消息。
        mOmsPortalOrderService.cancelOrder(orderId);
    }
}
